<template>
  <div class="ccui-home-index">
    <div class="ccui-app-container">
      <el-button
        size="mini"
        type="primary-font-mini"
        @click="$refs.exportQr.queryAutograph({ createUserId })"
        >签名</el-button
      >
      <img v-if="imgSrc" :src="imgSrc" />
      <empty v-else class="empty">
        <p slot="description">暂无签名</p>
      </empty>
      <!--二维码弹窗-->
      <exportQr ref="exportQr" type="edit" @ok="init()" />
    </div>
  </div>
</template>

<script>
import { getSessionItem } from "@/basa/utils";
import { qrySmpAutographById } from "@/basa/api";
import publicComponent from "@/basa/components/public";
export default {
  name: "index",
  components: {
    exportQr: publicComponent.exportQr,
    empty: publicComponent.empty
  },
  data() {
    return {
      imgSrc: "",
      createUserId: getSessionItem("userInfo").openId
    };
  },
  activated() {
    this.init();
  },
  methods: {
    async init() {
      const { base64Code } = (
        await qrySmpAutographById({ createUserId: this.createUserId })
      ).data.data;

      this.imgSrc = base64Code ? `data:image/png;base64,${base64Code}` : "";
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-button {
  display: block;
  margin-bottom: 15px;
}
.empty {
  height: 60vh;
}
</style>
